package org.flint92.springcloud.hystrix.controller;

import org.flint92.springcloud.hystrix.command.UserClientHystrixCommand;
import org.flint92.user.domain.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import java.util.List;

/**
 * @author flint92
 */
@RestController
public class UserController {

    private final RestTemplate restTemplate;

    @Autowired
    public UserController(RestTemplate restTemplate) {
        this.restTemplate = restTemplate;
    }

    @GetMapping("/user/list")
    @SuppressWarnings("unchecked")
    public List<User> findAll() {

//        String url = "http://spring-cloud-hystrix-provider/user-provider/list";
//
//        return restTemplate.getForObject(url, List.class);

        return new UserClientHystrixCommand("spring-cloud-hystrix-provider", restTemplate).execute();
    }

}
